package cn.lingyangwl.agile.system.assembly;

import cn.lingyangwl.agile.model.module.auth.UserDataRule;
import cn.lingyangwl.agile.model.module.auth.UserRole;
import cn.lingyangwl.agile.system.model.entity.SysMenuRule;
import cn.lingyangwl.agile.system.model.entity.SysRole;
import cn.lingyangwl.agile.system.model.entity.SysUser;
import cn.lingyangwl.agile.system.model.rqrs.tenant.TenantUserResp;
import cn.lingyangwl.agile.system.model.rqrs.user.*;
import cn.lingyangwl.framework.tool.core.StringUtils;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;

import java.util.List;

/**
 * @author shenguangyang
 */
@Mapper(componentModel = "spring")
public interface SysUserAssembly {

    @Mappings({
            @Mapping(source = "userId", target = "id")
    })
    UserResp toUserResp(SysUser source);

    @Mappings({
            @Mapping(source = "userId", target = "userId")
    })
    TenantUserResp toTenantUserResp(SysUser source);

    @Named("strToList")
    default List<Long> strToList(String item) {
        return StringUtils.toList(item, ",", Long.class);
    }

    SysUser toUser(UserRegisterReq source);

    @Mappings({
            @Mapping(source = "roleIds", target = "roleIds", qualifiedByName = "strToList"),
            @Mapping(source = "deptIds",target = "deptIds", qualifiedByName = "strToList")
    })
    SysUser toUser(UserSaveReq source);

    @Mappings({
            @Mapping(source = "id", target = "userId"),
            @Mapping(source = "deptIds", target = "deptIds", qualifiedByName = "strToList"),
            @Mapping(source = "roleIds", target = "roleIds", qualifiedByName = "strToList")
    })
    SysUser toUser(UserUpdateReq source);

    SysUser toUser(UserProfileUpdateReq source);

    SysUser toUser(UserPageReq source);

    DeptUserResp toDeptUserResp(SysUser source);

    UserDetailsResp toUserDetailsResp(UserResp source);

    UserDataRule toUserDataRule(SysMenuRule source);

    UserRole toUserRole(SysRole source);
}
